/***     
 * SP_FIVE_STRAIGHT_FLUSH: 12, // 同花顺牌
 */

var CardGroupType = require('./CardGroupType');
var FindSameCardTypeTool = require('../FindTool/FindSameCardTypeTool');
var _ = require('./../Underscore');
var CardType = require('./../CardType');
var CardTool = require('./../CardTool');
var FindShunZiTool = require('../FindTool/FindShunZiTool');
var GroupSameTypeShunZi = module.exports = {};


GroupSameTypeShunZi.getName = function() {
    return '同花顺牌';
};

GroupSameTypeShunZi.getType = function() {
    return CardGroupType.SP_FIVE_STRAIGHT_FLUSH;
};

/***
 * 获取结果
 * _cardInfoList：牌信息
 * return {
 *      isFind:(false or true 是否找到)
 *      findGroupMore:[[]] 为二维数组
 * }
 */
GroupSameTypeShunZi.getMoreResult = function(_cardInfoList) {
    var resultInfo = this.check(_cardInfoList);
    /***有可能有多组所以需要加工 */
    if (resultInfo.isFind) {
        var result = {
            isFind: true,
            findGroupMore: []
        }
        var findGroup = resultInfo.findGroup;

        _.each(findGroup, function(singleGroup) {
            var info = {
                findGroup: singleGroup,
                otherGroup: _.difference(_cardInfoList, singleGroup)
            };
            result.findGroupMore.push(info);
        });
        CardTool.LogResult(result, this.getName());
        return result;
    }
    CardTool.LogResult(resultInfo, this.getName());
    return resultInfo;
};

/***
 * 获取结果
 * _cardInfoList：牌信息
 * return {
 *      isFind:(false or true 是否找到)
 *      findGroup:[[]] 为二维数组
 * }
 */
GroupSameTypeShunZi.check = function(_cardInfoList) {
    var resultInfo = FindSameCardTypeTool.getResultAll(_cardInfoList);
    var findGroup = [];
    var otherGroup = [];
    if (resultInfo.isFind) {
        _.each(resultInfo.findGroup, function(group) {
            var _tmpResult = FindShunZiTool.getResult(group, 5);
            if (_tmpResult.isFind) {
                findGroup.push(_.flatten(_tmpResult.findGroup));
            }
            otherGroup.push(_tmpResult.otherGroup);
        }.bind(this));
    }
    var result = {
        isFind: _.size(findGroup) > 0,
        findGroup: findGroup,
        otherGroup: _.flatten(otherGroup)
    };
    return result;
}